<!DOCTYPE html>
<html lang="en-us" id="extr-page">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
	<form class="form-horizontal" onsubmit="return false" id="form">
		<input type="hidden" id="id" name="id">
		<fieldset>
			<div class="form-group">
				<label class="col-md-2 control-label">权限名</label>
				<div class="col-md-10">
					<input class="form-control" placeholder="权限名" type="text" name="name" id="name" maxlength="50"
						data-bv-notempty="true"
						data-bv-notempty-message="权限名 不能为空">
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-2 control-label">权限标识</label>
				<div class="col-md-10">
					<input class="form-control" placeholder="权限标识" type="text" name="permission" id="permission" readonly>
				</div>
			</div>

			<div class="form-actions">
				<div class="row" align="center">
					<div class="col-md-12">
						<button class="btn btn-primary" onclick="location.href='permissionList.html'">返回</button>
						<button class="btn btn-primary" type="submit" onclick="update()">
							<i class="fa fa-save"></i> 保存
						</button>
					</div>
				</div>
			</div>

		</fieldset>
	</form>
</div>

	<script src="../../js/constant.js"></script>
	<script type="text/javascript" src="../../js/libs/jquery-3.3.1.min.js"></script>
	<script type="text/javascript" src="../../js/jq.js"></script>
	<script type="text/javascript" src="../../js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
	<script type="text/javascript" src="../../js/common.js"></script>
	<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript">
	layui.use('layer', function(){
	    var layer = layui.layer;
	});
	
	initData();
	
	function initData(){
		$("#id").val(getUrlParam("id"));
		$("#name").val(decodeURIComponent(getUrlParam("name")));
		$("#permission").val(decodeURIComponent(getUrlParam("permission")));
	}
	
	function update() {
		$('#form').bootstrapValidator();
		var bootstrapValidator = $("#form").data('bootstrapValidator');
		bootstrapValidator.validate();
	    if(!bootstrapValidator.isValid()){
		   return;
	    }
	    
	    var formdata = $("#form").serializeObject();

		$.ajax({
			type : 'put',
			url : domainName + '/api-u/permissions',
			contentType: "application/json; charset=utf-8",  
			data : JSON.stringify(formdata),
			success : function(data) {
				layer.msg("成功", {shift: -1, time: 1000}, function(){
                    location.href = "permissionList.html";
                });
			}
		});
	}
		
</script>
</body>
</html>